package com.csii.pos.scalegrade.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csii.adhoc.exception.ParamValidityException;
import com.csii.adhoc.id.UidGenerator;
import com.csii.pos.scalegrade.BusnScaleGrdDef;
import com.csii.pos.scalegrade.BusnScaleGrdSu;
import com.csii.pos.scalegrade.mapper.BusnScaleGrdDefMapper;
import com.csii.pos.scalegrade.service.IBusnScaleGrdDefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Description: 划分业务规模档次的描述和档次设置
 * @Author: zhanghao
 * @Date:   2021-07-06
 * @Version: V1.0
 */
@Service
public class BusnScaleGrdDefServiceImpl extends ServiceImpl<BusnScaleGrdDefMapper, BusnScaleGrdDef> implements IBusnScaleGrdDefService {

    @Autowired
    private BusnScaleGrdDefMapper busnScaleGrdDefMapper;

    @Override
    public List<BusnScaleGrdDef> findAllScaleNameAndId() {
        List<BusnScaleGrdDef> busnScaleGrdDefs = busnScaleGrdDefMapper.selectList(null);
        return busnScaleGrdDefs;
    }

    @Override
    public IPage<BusnScaleGrdDef> queryPageList(Page<BusnScaleGrdDef> page, BusnScaleGrdDef busnScaleGrdDef) {


        return busnScaleGrdDefMapper.queryPageList(page, busnScaleGrdDef);
    }

    @Override
    public void addBusnScaleGrdDef(BusnScaleGrdDef busnScaleGrdDef) {
        //注释原因:利用MP自带生成主键
        //String id = String.valueOf(uidGenerator.getUID());
        //busnScaleGrdDef.setScaleGrdNo(id);

        //新增时ScaleGrdNm规模档次名称/ScaleGrdNum规模档次数量/FitIfbTools适用投融资工具都不能为空
        if (StringUtils.isEmpty(busnScaleGrdDef.getScaleGrdNm())){
            throw new ParamValidityException("ScaleGrdNm规模档次名称不能为空!");
        }
        if (StringUtils.isEmpty(busnScaleGrdDef.getScaleGrdNum().toString())){
            throw new ParamValidityException("ScaleGrdNum规模档次数量不能为空!");
        }
        if (StringUtils.isEmpty(busnScaleGrdDef.getFitIfbTools())){
            throw new ParamValidityException("FitIfbTools适用投融资工具不能为空!");
        }
        busnScaleGrdDefMapper.insert(busnScaleGrdDef);
    }

   /* @Override
    public boolean isExistData(BusnScaleGrdDef busnScaleGrdDef) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("SCALE_GRD_NO", busnScaleGrdDef.getScaleGrdNo());
        BusnScaleGrdDef one = busnScaleGrdDefMapper.selectOne(queryWrapper);
        boolean flag = false;
        if (one != null) {
            flag = true;
        }
        return flag;
    }*/
}
